//
//  ZYSBtnHeaderModels.m
//  budejie
//
//  Created by oldSix_Zhu on 16/8/27.
//  Copyright © 2016年 oldSix_Zhu. All rights reserved.
//

#import "ZYSBtnHeaderModels.h"
#import "OSZNetWorkTool.h"

@implementation ZYSBtnHeaderModels
+(instancetype)ZYSBtnHeaderModelsWithDic:(NSDictionary *)dic
{
    ZYSBtnHeaderModels *model = [[ZYSBtnHeaderModels alloc]init];
    
    [model setValuesForKeysWithDictionary:dic];
    
    return model;
    
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
    
}

+ (void)loadBtnHeaderWithUrlStr:(NSString *)urlStr successBlock:(void(^)(NSArray *array))successBlock failBlock:(void(^)(NSError *error))failBlock
{
    [[OSZNetWorkTool sharedOSZNetWorkTool]GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dic = responseObject;
        
        NSArray *arr = dic[@"top"];
        
        NSMutableArray *mArr = [NSMutableArray arrayWithCapacity:arr.count];
        
        [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            ZYSBtnHeaderModels *model = [ZYSBtnHeaderModels ZYSBtnHeaderModelsWithDic:obj];
            
            [mArr addObject:model];
        }];
        
        //排序
        [mArr sortUsingComparator:^NSComparisonResult(ZYSBtnHeaderModels *obj1, ZYSBtnHeaderModels *obj2) {
           
            return [obj1.fans_count compare:obj2.fans_count];
            
        }];
        
        if (successBlock)
        {
            successBlock(mArr.copy);
        }
        
  
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       
        if (failBlock)
        {
            failBlock(error);
        }
    }];
    
}




@end









